package Atest;

import netscape.security.UserTarget;
import org.junit.Test;

import java.util.*;

/**
 * @Author wangzhipeng
 * @Date 2020-08-18 11:19 上午
 * @Description
 */
public class demo {
    @Test
    public void test1(){
        int a = 12;
        a*=2+3;  //先做2+3
        System.out.println(a);

    }


    @Test
    public void test2(){
        if(true){   //只能是trueh或false
            System.out.println(111);
        }
    }

    @Test
    public void test3(){
        String s1 = "Hello!";
        String s2 = new String(new char[]{'1','d'});
    }

    @Test
    public void test4(){
        int[] a = new int[4];
        System.out.println(a[1]);//输出0

       // int[] a0 = new int[2]{1,4}; 错误 -> 声明数组的同时赋值时不能指定数组长度

        int[] a1 = new int[]{1,4}; //数组初始化

        int[] a4 = {1,4,5};

        System.out.println(a1.length);
        System.out.println(a1[4]);//运行时错误 java.lang.ArrayIndexOutOfBoundsException:

    }

    @Test
    public void test5(){
        //float型数组中的元素都是float，默认初始值是0.0。

        float[] a = new float[5];
        System.out.println(a[2]);  //输出0.0  而不是0
        double[] b = new double[5];
        System.out.println(b[2]); //输出0.0  而不是0
    }

    @Test
    public void test6(){
         //char[] c = "hello";  //报错

        String s = "hello";
        char[] chars = s.toCharArray(); //String -> char[]
        System.out.println(chars[2]);
        String s2 = new String(chars);  //char[] -> String
    }

    static String ss = "hello";
    public static void main(String[] args) {
        System.out.println(ss);
    }
    /**
     * @
     *
     * 形参是指在定义方法时参数列表中的参数，实参是指在调用方法时所传入的实际数据。
     * 形参是局部变量，作用域在方法体内，出了方法后不可见。 实参可以是字面量常量值也可以是变量，只要是可以在调用方法时传入的数据就是实参。
     * 形参是可以用 final 来修饰的，被 final 修饰的形参被赋初值后值不可以再改变
     */
    @Test
    public void test7(){
        String[] s1 = new String[10];
        System.out.println(s1[0]); //输出null
        System.out.println(s1.length);//输出10
    }

    @Test
    public void test8(){
        String s1 = "hello";
        int i = 0;
        System.out.println(i+s1);
        System.out.println(s1+i);
        //无运行错误
    }


    @Test
    public void test9(){
        String s1 = "hello";
        s1 = s1+10;
        System.out.println(s1);
       // s1[0]='a';//出错
        int i = s1.length();//数组才有length属性，字符串只有length()方法
    }

    String s22; //不初始化就可以输出null
    @Test
    public void test10(){
     //   String s11;  不初始化直接输出会报错
        String s11 = null;
        System.out.println(s11);
        System.out.println(s22);

    }

    @Test
    public void test11(){
        String aStr = "? One? ";
        String bStr = aStr;
        aStr.toUpperCase();
        aStr.trim();
        System.out.println("[" + aStr + "," + bStr + "]");
    }

    @Test
    public void test12(){
        String s1 = "hello";
        System.out.println(s1.charAt(3));
    }

    @Test
    public void test13(){
        String foo = "blue";
        String bar = foo;
        System.out.println(foo==bar); //true
        foo = "green";
        System.out.println(foo==bar); //false
        System.out.println(bar); //blue
    }

    @Test
    public void test14(){
        String s1 = "hello";
        int[] i = {1,4,5};
        System.out.println(s1.length()); //5   注意括号的有无
        System.out.println(i.length); //3
    }

    @Test
    public void test15(){
        String s1 = "hello";
        System.out.println(s1.indexOf("e"));  //返回int类型
        System.out.println(s1.charAt(1)); // 返回char
    }

    @Test
    public void test16(){
        Set<Short> s=new HashSet<Short>();
        for(Short i=0;i<100;i++) {
            s.add(i);
            s.remove((Short)i-1);
        }
        System.out.println(s.size());//100
        //i是Short类型i-1是int类型,其包装类为 Integer，所以s.remove(i-1);不能移除Set集合中Shor类型对象。


        Set<Integer> s2 = new HashSet<Integer>();
        s2.add(0);
        s2.remove(-1);
        System.out.println(s2.size());
    }

    @Test
    public void test17(){
        int i = 'A';
        System.out.println(i);//65
        int j = 'A'+'可';
        System.out.println(j);//21552
        //float f = 1.1;//报错
        float f1 = 1.1f;
        double f2 = 1.1;


        byte b = 3 + 5;
        char c = 98; c++;
        float f = 'a';
        System.out.println(f);
       // double d = 123456789012;//超过范围
        byte b1 = 'a';
        System.out.println(b1);

    }

    @Test
    public void test18(){
        // byte short/char  int long float double
    }

    @Test
    public void test19(){
        int[] i = new int[2];
        System.out.println(i[0]);//0
        float[] f = new float[2];
        System.out.println(f[0]);
        char[] a = new char[4];
        System.out.println(a[0]);//空
        boolean[] booleans = new boolean[4];
        System.out.println(booleans[0]);

        //引用类型默认值位null 引用类型在成员变量中会默认赋值null

    }

    public void demo(){ //方法可以和类名相同

    }

    private String name = "hello";
    @Test
    public void test21(){
        demo[] d = new demo[]{new demo(),new demo()};
        System.out.println(d.length);//2
        System.out.println(d[0].name);//hello

        demo[] d1 = new demo[2];
        System.out.println(d1.length);//2
        System.out.println(d1[0].name);//NullPointerException
    }

    @Test
    public void test22(){
        char i =65535;
        int j = 'A';
        System.out.println(i);
    }

    @Test
    public void test23(){
        int x=4;
        System.out.println("value is "+ ((x>4) ? 99.9 : 9));//9.0不是9
        HashMap map = new HashMap();
        map.put("name",null);
        map.put("name","xiyangyang");
        System.out.println(map.get("name"));
    }

    @Test
    public void test24() {
//        String s = "jion"+3;
//        int a1 = "join"+3;
//        int a = 'a'+5;
//        float f = 5+5.5F;
//        long l = 4990;
//        int i = 4L;
//        float f = 1.1;
//        double d = 34.4;
        int[] a;
        int b[] = new int[3];
//        int[] c;c={1,4};
//        int[] d = new int[3]{1,2,3};

        String s = new String("hello");
        String t = new String("hello");
        char c[] = {'h','e','l','l','o'};
        System.out.println(s.equals(t));
        System.out.println(s==t);
        System.out.println(t.equals(new String("hello")));

    }


}
